{extend name="base" /}
{block name="title"}编程资料免费下载{/block}


{block name="header"}
	{include file="public/user_header" /}
{/block}

{block name="content"}

<template class="iceView">
<div class="zbd-content">
	<div class="page mt10">
		<div class="row">
			<div class="w9">	
				
				<div class="box radius0">
					<div class="box-content">
						<div class="fax fax_bt">
							<span class="fax-pre fax-li {{pre_id == '' ? 'acv' : ''}}" i-onclick="clickPre" data-pid="" >全部</span>
							<span class="fax-pre fax-li {{pre_id == item.id ? 'acv' : ''}}" i-for="pre_list" i-index="index" i-item="item" i-onclick="clickPre" data-pid="{{item.id}}">
								{{item.name}}
							</span>
						</div>

						<div class="fax mt15">
							<span class="fax-pre fax-li-som {{som_id == '' ? 'acv2' : ''}}" i-onclick="clickSom" data-pid="" >全部</span>
							<span class="fax-li-som {{som_id == item.id ? 'acv2' : ''}}" i-for="som_list" i-index="index" i-item="item" i-onclick="clickSom" data-pid="{{item.id}}">
								{{item.name}}
							</span>
						</div>
					</div>
				</div>
				<div class="box radius0">
					<div class="box-content">
						<ul class="list">
							<li class="list-item" i-for="bookList" i-index="index" i-item="item">
								<span class="list-icon"><img src="/static/web/zbdui/src/img/{{item.suffix}}.png" class="align-middle book-icon"></span>
								<a href="/book/detail?id={{item.id}}" class="list-title book-a">{{item.title}}</a>
								<span class="list-time">{{item.create_time}}</span>
								<div class="book-li"><span class="orange mr20">{{item.pre.name}}</span><span class="green mr20">{{item.som.name}}</span><span class="mr25">大小：{{item.size ? item.size : '未知'}}</span><span class="mr25">下载：{{item.downloads_num ? item.downloads_num : 0}} 次</span><span class="mr25">预览：{{item.yulan ? item.yulan : 0}} </span></div>
							</li>
						</ul>
						<div class="p20 text-center" i-if="{{isNull}}">
							<img src="/static/web/zbdui/src/img/m.png" style="width: 150px;">
							<p class="text-center mt30">数据为空</p>
						</div>
					</div>
				</div>
				<p i-if="{{loadShow}}" class="text-center cursor-pointer small jiaz mb40" i-onclick="Next">{{loadTxt}}</p>
			</div>
			<div class="w3">
			<div class="tip bg-green tishiyude">每天收集好用的学习资料分享网友，全部免费下载分享，让学习更简单，提高自我编程能力，增值自我，成为大神！</div>

				<div class="box radius0">
					<div class="box-title icon ice-time">
						<div class="left">最新上传</div>
					</div>
					<div class="box-content">
						<ul class="list1">
							{foreach $nowList as $key => $val}
							<li class="list-item">
								<div class="list-round bg-green"></div>
								<div class="list-title"><a href="/book/detail?id={$val.id}" class="new-a">{$val['title']}</a></div>
								<div class="list-time">{$val['create_time']}</div>
							</li>
							{/foreach}
						</ul>

					</div>
				</div>

				<div class="box radius0">
					<div class="box-title gray icon ice-download">
						<div class="left">下载排行榜</div>
					</div>
					<div class="box-content">
						<ul class="list">
							{foreach $hotList as $key => $val}
							<li class="list-item">
								<span class="el"><span class="tag bg-co{$key+1}">{$key+1}</span><a class="ph-a" href="/book/detail?id={$val.id}">{$val['title']}</a></span>
							</li>
							{/foreach}
						</ul>
					</div>
				</div>

			</div>
		</div>
	</div>
</div>
</template>
<input type="hidden" id="pre_id" value="{$param['pre_id']}">
<input type="hidden" id="som_id" value="{$param['som_id']}">
<script src="/static/web/zbdui/src/view/iceView.js"></script>
<script type="text/javascript">

    ice.view({
    	isNull: false,
    	loadShow: true,
    	loadTxt: '点击加载更多',
    	bookList:[],
    	page: 1,
    	limit: 20,
    	pre_id: '', // 父级ID
    	som_id: '', // 子级ID
    	pre_list:[], // 父级分类
    	som_list:[], // 子级分类
    	bbsListShow: false,
    	Next: function(e){
    		// 下一页
    		var that = this;
    		that.page = parseInt(that.page + 1);
    		that.loadTxt = '正在准备编程资源...';
    		that.isNull = false;
    		that.loadShow = true;
    		that.getList('prepend');

    	},
    	getList: function(type){
    		var that = this
    		ice.ajax({
			    url:'/Book/ajaxBookList',
			    type:'get',
			    data: {
			    	'page': that.page,
			    	'limit': that.limit,
			    	'pre_id': that.pre_id,
			    	'som_id': that.som_id,
			    },
			    success:function(res){
			    	
			    	that.loadTxt = '点击加载更多'
			    	if(res.code == 1){
			    		ice.pop({content:res.message, icon: 'warning'})
			    		return false;
			    	}

			    	if(res.data.length > 0){
		    			if(type == 'html'){
		    				that.bookList = res.data
			    		} else{
			    			that.bookList = that.bookList.concat(res.data);
			    		}

			    		if(res.data.length < that.limit){
			    			that.loadShow = false;
			    		}
		    			ui.init();
		    		} else{
		    			that.loadShow = false;

		    			if(that.bookList.length == 0){
		    				that.isNull = true;
		    			}
		    		}
			    }
			});
    	},
    	clickSom: function(e){
    		// 点击二级分类
    		var that = this;

    		var SomId = ice(e).attr("data-pid")
    		if(SomId > 0){
    			that.som_id = SomId
    		} else{
    			that.som_id = ''
    		}
    		that.page = 1;
    		that.limit = 20;
    		that.isNull = false;
    		that.loadTxt = '正在准备编程资源...';
    		that.bookList = [];
    		that.loadShow = true;
    		that.getList('html')
    	},
    	clickPre: function(e){
    		// 点击父类
    		var that = this;
    		// 获取分类
    		var noPid = ice(e).attr("data-pid")
    		if(noPid > 0){
    			var arr = {
    				pid : noPid
    			}

    			that.pre_id = noPid
    		} else{
    			var arr = {
    				is_som : 'Y'
    			}
    			that.pre_id = ''
    		}

    		that.isNull = false;
    		that.loadTxt = '正在准备编程资源...';
    		that.bookList = [];
    		that.loadShow = true;

			ice.ajax({
			    url:'/BookType/getAjaxTypeSomList',
			    type:'get',
			    data: arr,
			    success:function(res){
			    	console.log(res)
			    	that.set({
		                som_list:res.data,
		                som_id: '',
		                page: 1,
		                limit: 20
		            })
		            that.getList('html')
					ui.init();
			    }
			});
    	},
    	onload: function(){
    		var that = this;
    		
    		that.set({
	            loadTxt:'正在准备编程资源...',
	        })

    		// 获取分类
			ice.ajax({
			    url:'/BookType/getAjaxTypeAllList',
			    type:'get',
			    data:'',
			    success:function(res){
			    	console.log(res)
			    	that.set({
		                pre_list:res.data.pre_list,
		                som_list:res.data.som_list,
		                pre_id: ice("#pre_id").val(),
		                som_id: ice("#som_id").val(),
		                loadTxt:'点击加载更多',
		            })
		            that.getList('html');
					ui.init();
			    }
			});
    	}
    })
</script>

{/block}